<?php

class Module_Mediate_CaseMediateLog extends Module_BaseModule
{
    use Lib_BaseTraitsModule;
    private static $obj = null;
    private $model = null;
    //调解类型
    public static $mediateType = array(
        '1' => '线上调解',
        '2' => '微信调解',
        '3' => '线下调解',
        '4' => '其他',
    );
    public static $mobileType = array(
        '1' => '合同号码',
        '2' => '移动修复',
        '3' => '联通修复',
    );
    /**
     * 封闭构造
     */
    public function __construct()
    {
        $this->model = new Model_Mediate_CaseMediateLog();
    }

    /**
     * 单例获取
     * 保证一条进程只产生一个Module对象
     * @return Module_Litigation_CaseMediateLog
     */
    public static function getInstance()
    {
        if (empty(self::$obj)) {
            self::$obj = new self();
        }
        return self::$obj;
    }


    public function getMediateLogByCaseId($caseIds,$where = [])
    {
        return $this->model->getMediateLogByCaseId($caseIds,$where);
    }

    //添加
    public function insert($mediate_data,$update_case = [])
    {
        if($mediate_data['callId'] && $mediate_data['caseId']){
            $history = $this->getOneByThirdId($mediate_data['caseId'],$mediate_data['callId']);
            if(empty($history)){
                return $this->model->insert($mediate_data,$update_case);
            }else{
                if(empty($mediate_data['mediateResult'])){
                    unset($mediate_data['mediateResult']);
                }
                if(empty($mediate_data['desc'])){
                    unset($mediate_data['desc']);
                }
                if(empty($mediate_data['nextTime'])){
                    unset($mediate_data['nextTime']);
                }
                unset($mediate_data['callId']);
                return $this->model->update($mediate_data,$update_case,$history['id']);
            }
        }
        return $this->model->insert($mediate_data,$update_case);
    }
    //根据第三方案件id获取数据
    public function getOneByThirdId($caseId,$callId){
        return $this->model->getOneByThirdId($caseId,$callId);

    }
}
